<?php
define ( '_FW_EXEC', 1 );

require '../core/sysProcess/define.php';

$request = $_SERVER['REQUEST_URI'];
$curFolder = dirname(__FILE__). '/';
$request = substr($request,strlen(SYS_ROOT_URL_WITHOUT_PROTOCOL) + 1);

$desPath = $curFolder.$request;

$reqArr = explode('/', $request);

$sizePos = count($reqArr) - 2;
$fileName = $reqArr[$sizePos + 1];
$size = $reqArr[$sizePos];

unset($reqArr[$sizePos]);
$realFile = $curFolder. implode('/', $reqArr);
if (!file_exists($realFile)) {
	$realFile = urldecode($realFile);
}
if (file_exists($realFile)) {
	include_once("resizeimage.inc.php");
	RCoreImporter::cls('helper.RFileFolderHelper');
	
	$size = substr($size, 5);
	$size = explode('x', $size);

	$desFolder = substr($desPath, 0, strlen($desPath) - strlen($fileName));
	RFileFolderHelper::checkAndCreateFolder($desFolder);
	
	header("Status: 200");
	header('Cache-Control: no-cache');
	
	$rimg=new RESIZEIMAGE($realFile);
	$rimg->setNewFilePath($desPath);
	$rimg->resize_limitwh($size[0], $size[1]);
	$rimg->close();
	if ($rimg->error()) {
		header("Status: 404");
	}
    die();
}
?>